// riscv64.rs
use sbi_rt::{NoReason, Shutdown, set_timer, system_reset};

use super::Timer;
use riscv::register::{sie, time};
use crate::INFO;
const CLOCK_FREQ: usize = 12500000;

impl Timer {
    #[inline]
    pub fn get_cur_timer() -> usize {
        time::read()
    }

    pub fn timer_init() {
        unsafe {
            sie::set_stimer();
        }
        Self::set_next_timeout();
        INFO!("timer_init done");
    }

    #[inline]
    pub fn set_next_timeout() {
        // Setting the timer through calling SBI.
        sbi_rt::set_timer((time::read() + CLOCK_FREQ / 100) as _);
    }
}
